using System.Data.Common;
using System.Data.SqlClient;
using DataAssociations.Repository.Connection.Interfaces;
using DataAssociations.Repository.Connection.ValidationRules;

namespace DataAssociations.Repository.Connection.Implementations
{
    public class SqlConnectionStringType : IConnectionStringType
    {
        private const int _connectionTimeoutDefalutValue = 10;

        public int? ConnectionTimeout { get; set; }

        [NonEmptyStringValidation]
        public string InitialCatalog { get; set; }

        [NonEmptyStringValidation]
        public string DataSource { get; set; }

        public string Password { get; set; }

        public string UserId { get; set; }

        public bool IntegratedSecurity { get; set; }

        public DbConnectionStringBuilder BuildConnectionString()
        {
            var builder = new SqlConnectionStringBuilder();
            builder.ConnectTimeout = ConnectionTimeout ?? _connectionTimeoutDefalutValue;
            builder.InitialCatalog = InitialCatalog;
            builder.DataSource = DataSource;
            builder.Password = Password;
            builder.UserID = UserId;
            builder.IntegratedSecurity = IntegratedSecurity;
            return builder;
        }

        public string DataBaseManagementSystemName
        {
            get { return "Sql Database"; }
        }
    }
}